﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Xml;

namespace Financial
{
    class NewsStory
    {
        public NewsStory() { }

        public static ArrayList CreateNewsStoryList(String company)
        {
            ArrayList newsStories = new ArrayList();
            XmlDocument doc = new XmlDocument();
            XmlTextReader reader = new XmlTextReader
                ("http://news.search.yahoo.com/rss?ei=UTF-8&p=" + company + "&fr=news-us-ss");
            reader.WhitespaceHandling = WhitespaceHandling.Significant;
            doc.Load(reader);
            XmlNodeList items = doc.GetElementsByTagName("item");
            XmlNodeList titles = doc.GetElementsByTagName("title");
            XmlNodeList links = doc.GetElementsByTagName("link");
            XmlNodeList pubDates = doc.GetElementsByTagName("pubDate");
            for (int i = 1; i < items.Count; i++)
            {
                NewsStory story = new NewsStory();
                story.Title = titles[i].InnerText;
                story.Link = links[i].InnerText;
                story.pubDate = pubDates[i].InnerText;
                newsStories.Add(story);
            }
            return newsStories;
        }

        public String Title { set; get; }
        public String Link { set; get; }
        public String pubDate { set; get; }
    }
}
